import axios from 'axios'
import { UniAdapter } from "uniapp-axios-adapter";
import { cookieTokenName, getToken, removeToken } from '../auth';
import Toast from '@vant/weapp/dist/toast/toast';
import config from '@/config/config.json'
import { goWebview } from '@/utils/index.js';
import { responseHandle } from './requestHandle';
export const service = axios.create({
  baseURL: `${config.siteDomain}${import.meta.env.VITE_GLOB_API_URL}`,
  adapter: UniAdapter, // 指定适配器
})


// 统一注入token
service.interceptors.request.use((config = {}) => {
  const token = getToken();
  if (token) {
    config.headers[cookieTokenName] = token;
  }
  return config;
});


service.interceptors.response.use((res) => {
  return responseHandle(res);
});



export function get({ url, params, responseType }) {
  return service({
    url,
    method: 'GET',
    params,
    responseType
  })
}

export function post({ url, data }) {
  return service({
    url,
    method: 'POST',
    data
  })
}



export default service
